package net.ibizsys.eclipse.studio.xml;

import java.util.Collections;

import org.w3c.dom.Node;

import net.ibizsys.eclipse.studio.util.StringKit;

/**
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class IBizWF extends IBizSearchableNode
{
	public static final String NODE_PSWORKFLOW = "PSWORKFLOW";

	/**
	 * 代码名称
	 */
	public static final String ATTR_CODENAME = "CODENAME";

	private String codeName;

	private IBizWFVersionList versionList = new IBizWFVersionList();

	@Override
	protected void initAttribute(String name, String value)
	{
		if (StringKit.IsEqual(ATTR_CODENAME, name, true))
		{
			this.codeName = value;
			return;
		}

		super.initAttribute(name, value);
	}

	@Override
	protected void initChildNode(Node node, IBizProject project)
	{
		if (StringKit.IsEqual(node.getNodeName(), IBizWFVersionList.NODE_PSWFVERSIONS, true))
		{
			versionList.init(node, project);
			return;
		}

		super.initChildNode(node, project);
	}

	public String getCodeName()
	{
		return codeName;
	}

	@Override
	public String getDesc()
	{
		return getCodeName();
	}

	public IBizWFVersionList getVersionList()
	{
		return versionList;
	}

	@Override
	public boolean match(String keyword)
	{
		if (super.match(keyword))
		{
			return true;
		}
		if (StringKit.has(getText(), keyword) || StringKit.has(NODE_PSWORKFLOW, keyword))
		{
			return true;
		}

		return false;
	}
	
	@Override
	public void sortChildren()
	{
		Collections.sort(versionList, new XmlNodeTextComparator<XmlNode>());
	}
}
